home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / decprom / fileLoad.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-17  |  2.5 KB  |  102 lines

  1. /* 
  2.  * fileLoad.c --
  3.  *
  4.  *    The routine to load a program into main memory.
  5.  *
  6.  * Copyright 1986 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. #ifdef notdef
  11. static char rcsid[] = "$Header: /sprite/src/boot/decprom/RCS/fileLoad.c,v 1.1 90/02/16 16:14:08 shirriff Exp $ SPRITE (Berkeley)";
  12. #endif not lint
  13.  
  14. #include "sprite.h"
  15. #include "fsBoot.h"
  16. #include "kernel/procMach.h"
  17. #include "kernel/machMon.h"
  18. #include "boot.h"
  19.  
  20. #define KERNEL_ENTRY KERNEL_START
  21.  
  22.  
  23. /*
  24.  *----------------------------------------------------------------------
  25.  *
  26.  * FileLoad --
  27.  *
  28.  *    Read in the kernel object file.  This is loaded into memory at
  29.  *    a pre-defined location (in spite of what is in the a.out header)
  30.  *    for compatibility with Sun/UNIX boot programs.  The Sprite kernel
  31.  *    expects to be loaded into the wrong place and does some re-mapping
  32.  *    to relocate the kernel into high virtual memory.
  33.  *
  34.  * Results:
  35.  *    The entry point.
  36.  *
  37.  * Side effects:
  38.  *    None.
  39.  *
  40.  *----------------------------------------------------------------------
  41.  */
  42.  
  43.  
  44. int
  45. FileLoad(handlePtr)
  46.     register Fsio_FileIOHandle    *handlePtr;
  47. {
  48.     ProcExecHeader    aout;
  49.     int            bytesRead;
  50.     register int    *addr;
  51.     register ReturnStatus status;
  52.     register int    i;
  53.     register int    numBytes;
  54.  
  55.     /*
  56.      * Read a.out header.
  57.      */
  58.  
  59.     status = Fs_Read(handlePtr, 0, sizeof(aout), &aout, &bytesRead);
  60.     if (status != SUCCESS || bytesRead != sizeof(aout)) {
  61.     Mach_MonPrintf("No a.out header");
  62.     goto readError;
  63.     } else if (aout.aoutHeader.magic != PROC_OMAGIC) {
  64.     Mach_MonPrintf("A.out? mag %x size %d+%d+%d\n",
  65.         aout.aoutHeader.magic, aout.aoutHeader.codeSize,
  66.         aout.aoutHeader.heapSize, aout.aoutHeader.bssSize);
  67.     return(-1);
  68.     }
  69.  
  70.     /*
  71.      * Read the code and initialized data.
  72.      */
  73.  
  74.     numBytes = aout.aoutHeader.codeSize + aout.aoutHeader.heapSize;
  75.     Mach_MonPrintf("Size: %d+%d", aout.aoutHeader.codeSize,
  76.         aout.aoutHeader.heapSize);
  77.     status = Fs_Read(handlePtr, PROC_CODE_FILE_OFFSET(aout), numBytes,
  78.               aout.aoutHeader.codeStart, &bytesRead);
  79.  
  80.     if (status != SUCCESS) {
  81. readError:
  82.     Mach_MonPrintf("\nRead error <%x>\n", status);
  83.     return(-1);
  84.     } else if (bytesRead != numBytes) {
  85. shortRead:
  86.     Mach_MonPrintf("\nShort read (%d)\n", bytesRead);
  87.     return(-1);
  88.     }
  89.  
  90.     /*
  91.      * Zero out the bss.
  92.      */
  93.  
  94.     numBytes = aout.aoutHeader.bssSize;
  95.     Mach_MonPrintf("+%d\n", numBytes);
  96.     addr = (int *) (KERNEL_ENTRY + aout.aoutHeader.codeSize +
  97.         aout.aoutHeader.bssSize);
  98.     bzero(addr, numBytes);
  99.  
  100.     return ((int)aout.aoutHeader.entry);
  101. }
  102.